import {
    AfterContentChecked, AfterViewChecked, AfterViewInit, Component, ElementRef, Input, OnChanges, OnDestroy, OnInit,
    ViewChild
} from '@angular/core';
import {ServerSocket} from '@core/services/ws.service';

@Component({
  selector: 'app-c-weibo',
  templateUrl: './c-weibo.component.html',
  styleUrls: ['./c-weibo.component.less']
})
export class CWeiboComponent implements OnInit, AfterViewChecked , OnDestroy, OnChanges, AfterContentChecked {

  @Input() data;
  @Input() socket;
  @Input() IPPORT;
  @ViewChild('answer') box: ElementRef;
  @ViewChild('list') list: ElementRef;
  constructor(public ws: ServerSocket) { }

  ngOnInit() {

  }

    _answerList = [];
    // 正式时为父组件socket接收数据 @Input()至此组件;
    @Input()
    set answerList(value) {
        this._answerList = value;
        this.box.nativeElement.scrollTop = this.list.nativeElement.offsetHeight - this.box.nativeElement.offsetHeight;
    }

    get answerList() {
        return this._answerList;
    }
  //  answerList = [];
  // 测试
  // time;


  ngAfterContentChecked() {
  }

    ngAfterViewChecked() {
        this.box.nativeElement.scrollTop = this.list.nativeElement.offsetHeight - this.box.nativeElement.offsetHeight;
    }

  ngOnDestroy() {
       // clearInterval(this.time);
  }

  ngOnChanges() {
      this.box.nativeElement.scrollTop = this.list.nativeElement.offsetHeight - this.box.nativeElement.offsetHeight;
  }

}
